package top.shiyiri.servlet;

import top.shiyiri.pojo.Student;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

/**
 * @author Aunean
 * @date 2022/1/29 19:39
 */
public class SearchStudentServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取请求的参数
        //发送SQL语句查询学生的信息
        //使用for循环生成的数据模拟
        ArrayList<Student> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            int id = i + 1;
            list.add(new Student(id, "name_" + id, id + 20, "phone_"+id));
        }

        //保存查询到的结果到request域中
        req.setAttribute("list", list);
        //请求转发到 showStudent.jsp 页面
        req.getRequestDispatcher("/test/showStudent.jsp").forward(req, resp);
    }
}
